<template>
	<view class="mainbgc" v-if="pageShow">
		<header-top :messageInfo="{typeFlag:true,message:titletext,liner:false}"></header-top>
		<view class="chuqinbox ffffff mainpadding flexbetween">
			<view class="box1">
				<view class="renshu">{{allMsg.zc_days}}
					<text class="rentext">次</text>
				</view>
				<view class="chuqin">正常出勤</view>
			</view>
			<view class="box1">
				<view class="renshu" style="color: #FF0000 ;">{{allMsg.qq_days}}
					<text class="rentext">次</text>
				</view>
				<view class="chuqin">缺勤</view>
			</view>
			<view class="box1">
				<view class="renshu" style="color: #FF0000 ;">{{allMsg.ycqq_days}}
					<text class="rentext">次</text>
				</view>
				<view class="chuqin">异常出勤</view>
			</view>
			<view class="box1">
				<view class="renshu">{{allMsg.qj_num}}
					<text class="rentext">次</text>
					<view class="chuqin">请假</view>
				</view>
			</view>
			<view class="box1">
				<view class="renshu">{{allMsg.xx_days}}
					<text class="rentext">天</text>
					<view class="chuqin">休息</view>
				</view>
			</view>
		</view>
		<view class="strongtext  mainpadding">
			<text class="titletext textliner">考勤详情</text>
		</view>
		<view class="paddingbom">
			<view class="mainpadding ffffff flexbetween xiangqingbox" v-for="(item,index) in list" :key="index"
				@click="kaoqinxq(item)">
				<view class="left" style="display: flex;">
					<view class="flextops dingwei">
						<view class="huisetext yibai">{{item.date_value}}</view>
						<view class="">
							<view class="jindutbox">
								<view class="jindutyuan"></view>
								<view class="jindut" v-show="index+1 != list.length"></view>
							</view>
						</view>
					</view>
					<view class="qiandaotime">
						<view class="qiandao" style="margin-bottom: 16rpx;">
							签到：{{item.start_record?item.start_record.signtime_text : "暂无打卡"}}</view>
						<view class="qiandao">签退：{{item.end_record?item.end_record.signtime_text : "暂无打卡"}}</view>
					</view>
				</view>
				<view class="right flexleft" v-if="item.kqinfo">
					<view class="xiangqing">
						<!-- 0=正在打卡,10=缺勤,20=脱岗,30=正常,40=迟到脱岗,50=迟到,60=旷工脱岗,70=旷工 -->
						<template v-if="item.kqinfo.type==2">
							<view class="zhengchang">休息</view>
						</template >
						<template v-else>
							<view class="zhengchang" v-show="item.kqinfo.status==0">打卡中</view>
							<view class="tuokang" v-show="item.kqinfo.status==10">缺勤</view>
							<view class="tuokang" v-show="item.kqinfo.status==20">{{item.kqinfo.type==3?"加班":""}}脱岗</view>
							<view class="zhengchang" v-show="item.kqinfo.status==30">{{item.kqinfo.type==3?"加班":""}}正常</view>
							<view class="tuokang" v-show="item.kqinfo.status==40">{{item.kqinfo.type==3?"加班":""}}迟到脱岗</view>
							<view class="tuokang" v-show="item.kqinfo.status==50">{{item.kqinfo.type==3?"加班":""}}迟到</view>
							<view class="tuokang" v-show="item.kqinfo.status==60">{{item.kqinfo.type==3?"加班":""}}旷工脱岗</view>
							<view class="tuokang" v-show="item.kqinfo.status==70">{{item.kqinfo.type==3?"加班":""}}旷工</view>
						</template>
					</view>
					<view class="righticon2"></view>
				</view>
			</view>
		</view>

		<view class="bottombox ffffff mainpaddin flexbetween">
			<view class="bottmo-box1 flexleft" @click="upmonth">
				<view class="iconbox1">
					<image src="../../../static/image/system/youjiantou.png" mode=""></image>
				</view>
				<view class="wenben">上一月</view>
			</view>
			<view class="bottom-line "></view>
			<view class="bottmo-box2 flexleft ">
				<view class="iconbox" style="margin-bottom: 10rpx;">
					<image src="../../../static/image/system/rili.png" mode=""></image>
				</view>
				<view class="wenben">{{time}}</view>
			</view>
			<view class="bottom-line "></view>
			<view class="bottmo-box2 flexleft " @click="downmonth">
				<view class="wenben margin_right1">下一月</view>
				<view class="iconbox1">
					<image src="../../../static/image/system/zuojiantou.png" mode=""></image>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				time: "",
				month: 0,
				allMsg: {},
				list: [],
				listid: "",
				titletext: "我的考勤",
				pageShow:false
			}
		},
		onLoad(options) {
			if (options.id) {
				this.titletext = '考勤详情'
				this.listid = options.id
			}
			this.reset()
		},
		watch: {
			time() {
				this.getmykq()
			}
		},
		methods: {
			upmonth() {
				this.month = Number(this.month) + 1
				// console.log(httpRequest.getMonthDay(2, -1), "上一月和下一天")
				let date = httpRequest.getMonthDay(this.month, "")
				// 如果当前时间与返回回来的时间重合返回上一状态
				if (this.time == date) {
					this.month = Number(this.month) - 1
					return false
				} else {
					this.time = date
				}
			},
			downmonth() {
				if (this.month <= 0) {
					return false
				}
				this.month = Number(this.month) - 1
				if (this.month == 0) {
					this.reset()
					return false
				}
				// console.log(httpRequest.getMonthDay(2, -1), "上一月和下一天")
				this.time = httpRequest.getMonthDay(this.month, "")
			},
			getmykq() {
				let data = {
					search_time: this.time,
					staff_id:this.listid
				}
				httpRequest.request('/dhtapi/user/kqDetail', 'POST', data, false, false, true).then(
				res => {
					this.list = res.data.reverse()
				})
				httpRequest.request('/dhtapi/user/kqData', 'POST', data, false, false, true).then(
				res => {
					this.allMsg = res.data
					this.pageShow = true
				})
			},
			reset() {
				let timeStr = httpRequest.dateTimeStr('y-m'); // y:年 m:月 d:日 h:时 i:分 s:秒 中间的分割符号可更改
				this.time = timeStr
			},
			kaoqinxq(item) {
				if (item.start_record && item.start_record.signtime_text) {
					uni.navigateTo({
						url: "/pages/workbench/xiaoshou/dakamx?id=" + item.kqinfo.id
					})
				} else {
					httpRequest.toast('无打卡记录，无法进入')
					return false
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.margin_right1{
		margin-right: 10rpx;
	}
	.huisetext {
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.yibai {
		margin-right: 100rpx;
	}

	.dingwei {
		position: relative;
	}

	.jindutyuan {
		width: 18rpx;
		height: 18rpx;
		position: absolute;
		top: -2rpx;
		right: -8rpx;
		border-radius: 50%;
		background: #D9D9D9;
	}

	.jindutbox {
		position: absolute;
		top: 0rpx;
		left: 100rpx;
	}

	.jindut {
		width: 1rpx;
		height: 159rpx;
		background-color: #BEC0BF;
	}

	.yuefens:nth-child(2n) {
		background: #FAFAFA;
	}

	.attendance {
		font-size: 28rpx;
		text-align: center;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.flex1 {
		flex: 1.5;
	}

	.dingbuwb {
		text-align: center;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.Employee {
		text-align: center;
	}

	.bottombox {
		position: fixed;
		width: 100%;
		left: 0;
		bottom: 0;

		box-sizing: border-box;
		padding: 30rpx 40rpx 70rpx;
	}

	.houtian {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #999999;
		margin-right: 10rpx;
	}

	.wenben {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
		margin-left: 10rpx;
	}

	.bottom-line {
		height: 44rpx;
		width: 2rpx;
		background-color: rgba(153, 153, 153, .1);
	}

	.iconbox1 {
		width: 28rpx;
		height: 28rpx;

		image {
			margin-bottom: 10rpx;
			width: 100%;
			height: 100%;
		}
	}

	.iconbox {
		margin-bottom: 4rpx;
		width: 28rpx;
		height: 28rpx;

		image {
			margin-bottom: 4rpx;
			width: 100%;
			height: 100%;
		}
	}


	.xiangqingbox:nth-child(2n) {
		background: #FAFAFA;
	}

	.xiangqing {
		margin-right: 36rpx;
	}

	.zhengchang {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}

	.tuokang {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF0000;
		margin-top: 22rpx;
	}

	.qiandao {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.mingzi {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		margin-bottom: 6rpx;
	}

	.yewuyuan {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.line {
		height: 42rpx;
		width: 2rpx;
		margin: 0 54rpx 0 32rpx;
		background-color: rgba(0, 0, 0, .1);
	}

	.chuqin {
		margin-top: 16rpx;
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.rentext {
		font-size: 20rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.renshu {
		text-align: center;
		font-size: 40rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
	}

	.focustext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}

	.nofocustext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000;
	}

	.fenge {
		width: 1rpx;
		height: 28rpx;
		background-color: rgba(153, 153, 153, .3);
	}

	.paddingbom {
		padding-bottom: 150rpx;
	}
</style>
